package com.ruoyi.am.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.am.mapper.AmDrivingMapper;
import com.ruoyi.am.domain.AmDriving;
import com.ruoyi.am.service.IAmDrivingService;
import com.ruoyi.common.core.text.Convert;

/**
 * 行车日志Service业务层处理
 * 
 * @author hkkk
 * @date 2020-11-29
 */
@Service
public class AmDrivingServiceImpl implements IAmDrivingService 
{
    @Autowired
    private AmDrivingMapper amDrivingMapper;

    /**
     * 查询行车日志
     * 
     * @param drivingId 行车日志ID
     * @return 行车日志
     */
    @Override
    public AmDriving selectAmDrivingById(Long drivingId)
    {
        return amDrivingMapper.selectAmDrivingById(drivingId);
    }

    /**
     * 查询行车日志列表
     * 
     * @param amDriving 行车日志
     * @return 行车日志
     */
    @Override
    public List<AmDriving> selectAmDrivingList(AmDriving amDriving)
    {
        return amDrivingMapper.selectAmDrivingList(amDriving);
    }

    /**
     * 新增行车日志
     * 
     * @param amDriving 行车日志
     * @return 结果
     */
    @Override
    public int insertAmDriving(AmDriving amDriving)
    {
        amDriving.setCreateTime(DateUtils.getNowDate());
        return amDrivingMapper.insertAmDriving(amDriving);
    }

    /**
     * 修改行车日志
     * 
     * @param amDriving 行车日志
     * @return 结果
     */
    @Override
    public int updateAmDriving(AmDriving amDriving)
    {
        return amDrivingMapper.updateAmDriving(amDriving);
    }

    /**
     * 删除行车日志对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAmDrivingByIds(String ids)
    {
        return amDrivingMapper.deleteAmDrivingByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除行车日志信息
     * 
     * @param drivingId 行车日志ID
     * @return 结果
     */
    @Override
    public int deleteAmDrivingById(Long drivingId)
    {
        return amDrivingMapper.deleteAmDrivingById(drivingId);
    }

    @Override
    public List<AmDriving> getListByMonth(){
        int month=new Date().getMonth()+1;
        List<AmDriving> list=amDrivingMapper.selectAmDrivingList(new AmDriving());
        List<AmDriving> temp=new ArrayList<>();
        for(AmDriving amDriving:list){
            if(amDriving.getDrivingTime().getMonth()==month){
                temp.add(amDriving);
            }
        }
        return temp;
    }
}
